require 'clear_taobao_title'
require 'dict'
require 'iconv'
require '../db_help/db_help' 


db_config = {"host" => '118.126.2.138', 'encoding' => 'utf8', 'username' => 'root', 'password' => 'admin', 'database' => 'tao_hidoudou'}

#=begin
db_help = DBHelp::DBHelp.create(db_config)
item_count = db_help.query("select count(id) as item_count from tao_items ").fetch_row()[0]

items = db_help.query("select i.id, i.iid, i.num_iid, i.title, s.nick, s.goods_no from tao_items i left join spider_items s on i.num_iid = s.num_iid where i.status <> 1 order by i.id " )
items.each_hash do |item|
	begin
		item_str = {:title => item["title"], 
							:good_no => item["goods_no"],
							:nick => item["nick"],
							:num_iid => item["num_iid"]
							}
		cl = ClearTaobaoTitle.new(item_str)
		ret_title = cl.filter()
		#puts "-- #{ret_title} --"
		db_help.query("update tao_items set format_title = '#{db_help.escape(ret_title)}', status = 1 where id = #{item['id']}")
	rescue
		next
	end
end
